/* $Id:rule.h $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#ifndef __RULE_H
#define __RULE_H

#include <string>
#include <map>
#include <list>
using namespace std;



class rule {
    int nr;
    int link;
    string name;
    string description;
public:
    rule();

    // Field : nr
    const int getNr() const;
    void setNr(const int v);
    int operator<(const class rule &ck) const;

    // Field : link
    enum link_enum{link_chapter,link_rule,link_paragraph,link_background,link_race,link_jobs,link_culture,link_deity,link_skill,link_item,link_aging,link_gender,link_action};
    const int getLink() const;
    const string showLink() const;
    void setLink(const int v);
    void setLink(const string v);

    // Field : name
    const string getName() const;
    void setName(const string v);

    // Field : description
    const string getDescription() const;
    void setDescription(const string v);

    void save(class channel &ch);
    void load(class channel &ch);
    void xml(ofstream &f, int l=0, int r=0);
};

// Repository

#define loopRules(v) loopSingle(rule_repo.listRule(),v,class rule,list)

class ruleRepository {
    map<string,rule> rules;
    int max_nr;
public:
    ruleRepository();
    class rule& getRule(const string v);
    void setRule(class rule& v);
    list<class rule>& listRule();
    void delRule(const string v);
    const bool isRule(const string v) const;
    multimap<string, sigc::signal<void, class rule& > > relations;
    bool load(class channel &ch);
    void save(class channel &ch);
};

extern ruleRepository rule_repo;

#endif // __RULE_H
